home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Zoners Half-Life Tools / hlrad / qrad.h < prev    next >
C/C++ Source or Header  |  2002-12-09  |  17KB  |  501 lines

  1. #ifndef HLRAD_H__
  2. #define HLRAD_H__
  3.  
  4. #if _MSC_VER >= 1000
  5. #pragma once
  6. #endif
  7.  
  8. #include "cmdlib.h"
  9. #include "messages.h"
  10. #include "win32fix.h"
  11. #include "log.h"
  12. #include "hlassert.h"
  13. #include "mathlib.h"
  14. #include "bspfile.h"
  15. #include "winding.h"
  16. #include "scriplib.h"
  17. #include "threads.h"
  18. #include "blockmem.h"
  19. #include "filelib.h"
  20. #include "winding.h"
  21.  
  22. #ifdef SYSTEM_WIN32
  23. #pragma warning(disable: 4142 4028)
  24. #include <io.h>
  25. #pragma warning(default: 4142 4028)
  26. #endif
  27.  
  28. #ifdef HAVE_UNISTD_H
  29. #include <unistd.h>
  30. #endif
  31.  
  32. #ifdef HAVE_FCNTL_H
  33. #include <fcntl.h>
  34. #endif
  35.  
  36. #ifdef STDC_HEADERS
  37. #include <ctype.h>
  38. #endif
  39.  
  40. #ifdef SYSTEM_WIN32
  41. #include <direct.h>
  42. #endif
  43.  
  44. #define DEFAULT_LERP_ENABLED        true
  45. #define DEFAULT_FADE                1.0
  46. #define DEFAULT_FALLOFF             2
  47. #define DEFAULT_BOUNCE              1
  48. #define DEFAULT_DUMPPATCHES         false
  49. #define DEFAULT_AMBIENT_RED         0.0
  50. #define DEFAULT_AMBIENT_GREEN       0.0
  51. #define DEFAULT_AMBIENT_BLUE        0.0
  52. #define DEFAULT_MAXLIGHT            256.0
  53. #define DEFAULT_TEXSCALE            true
  54. #define DEFAULT_CHOP                64.0
  55. #define DEFAULT_TEXCHOP             32.0
  56. #define DEFAULT_LIGHTSCALE          1.0
  57. #define DEFAULT_DLIGHT_THRESHOLD    25.0
  58. #define DEFAULT_DLIGHT_SCALE        2.0
  59. #define DEFAULT_SMOOTHING_VALUE     50.0
  60. #define DEFAULT_INCREMENTAL         false
  61.  
  62. #ifdef ZHLT_PROGRESSFILE // AJM
  63. #define DEFAULT_PROGRESSFILE NULL // progress file is only used if g_progressfile is non-null
  64. #endif
  65.  
  66. // ------------------------------------------------------------------------
  67. // Changes by Adam Foster - afoster@compsoc.man.ac.uk
  68.  
  69. // superseded by DEFAULT_COLOUR_LIGHTSCALE_*
  70. #ifndef HLRAD_WHOME
  71.    #define DEFAULT_LIGHTSCALE          1.0
  72. #endif
  73.  
  74. // superseded by DEFAULT_COLOUR_GAMMA_*
  75. #ifndef HLRAD_WHOME
  76.    #define DEFAULT_GAMMA               0.5
  77. #endif
  78. // ------------------------------------------------------------------------
  79.  
  80. #define DEFAULT_INDIRECT_SUN        1.0
  81. #define DEFAULT_EXTRA               false
  82. #define DEFAULT_SKY_LIGHTING_FIX    true
  83. #define DEFAULT_CIRCUS              false
  84. #define DEFAULT_CORING              1.0
  85. #define DEFAULT_SUBDIVIDE           true
  86. #define DEFAULT_CHART               false
  87. #define DEFAULT_SKYCLIP             true
  88. #define DEFAULT_INFO                true
  89. #define DEFAULT_ALLOW_OPAQUES       true
  90.  
  91. // ------------------------------------------------------------------------
  92. // Changes by Adam Foster - afoster@compsoc.man.ac.uk
  93. #ifdef HLRAD_WHOME
  94.  
  95. #define DEFAULT_COLOUR_GAMMA_RED        0.5
  96. #define DEFAULT_COLOUR_GAMMA_GREEN        0.5
  97. #define DEFAULT_COLOUR_GAMMA_BLUE        0.5
  98.  
  99. #define DEFAULT_COLOUR_LIGHTSCALE_RED        1.0
  100. #define DEFAULT_COLOUR_LIGHTSCALE_GREEN        1.0
  101. #define DEFAULT_COLOUR_LIGHTSCALE_BLUE        1.0
  102.  
  103. #define DEFAULT_COLOUR_JITTER_HACK_RED        0.0
  104. #define DEFAULT_COLOUR_JITTER_HACK_GREEN    0.0
  105. #define DEFAULT_COLOUR_JITTER_HACK_BLUE        0.0
  106.  
  107. #define DEFAULT_JITTER_HACK_RED            0.0
  108. #define DEFAULT_JITTER_HACK_GREEN        0.0
  109. #define DEFAULT_JITTER_HACK_BLUE        0.0
  110.  
  111. #define DEFAULT_DIFFUSE_HACK            true
  112. #define DEFAULT_SPOTLIGHT_HACK            true
  113.  
  114. #define DEFAULT_SOFTLIGHT_HACK_RED        0.0
  115. #define DEFAULT_SOFTLIGHT_HACK_GREEN        0.0
  116. #define DEFAULT_SOFTLIGHT_HACK_BLUE        0.0
  117. #define DEFAULT_SOFTLIGHT_HACK_DISTANCE     0.0
  118.  
  119. #endif
  120. // ------------------------------------------------------------------------
  121.  
  122. // O_o ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  123. // Changes by Jussi Kivilinna <hullu@unitedadmins.com> [http://hullu.xtragaming.com/]
  124. #ifdef HLRAD_HULLU
  125.     // Transparency light support for bounced light(transfers) is extreamly slow 
  126.     // for 'vismatrix' and 'sparse' atm. 
  127.     // Only recommended to be used with 'nomatrix' mode
  128.     #define DEFAULT_CUSTOMSHADOW_WITH_BOUNCELIGHT false
  129.  
  130.     // RGB Transfers support for HLRAD .. to be used with -customshadowwithbounce
  131.     #define DEFAULT_RGB_TRANSFERS false
  132. #endif
  133. // o_O ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  134.  
  135.  
  136. #ifdef SYSTEM_WIN32
  137. #define DEFAULT_ESTIMATE    false
  138. #endif
  139. #ifdef SYSTEM_POSIX
  140. #define DEFAULT_ESTIMATE    true
  141. #endif
  142.  
  143. // Ideally matches what is in the FGD :)
  144. #define SPAWNFLAG_NOBLEEDADJUST    (1 << 0)
  145.  
  146. // DEFAULT_HUNT_OFFSET is how many units in front of the plane to place the samples
  147. // Unit of '1' causes the 1 unit crate trick to cause extra shadows
  148. #define DEFAULT_HUNT_OFFSET 0.5
  149. // DEFAULT_HUNT_SIZE number of iterations (one based) of radial search in HuntForWorld
  150. #define DEFAULT_HUNT_SIZE   11
  151. // DEFAULT_HUNT_SCALE amount to grow from origin point per iteration of DEFAULT_HUNT_SIZE in HuntForWorld
  152. #define DEFAULT_HUNT_SCALE 0.1
  153.  
  154. // If patches are allowed to be closer, the light gets amplified (which looks really damn weird)
  155. #define MINIMUM_PATCH_DISTANCE 1.01
  156.  
  157. //
  158. // LIGHTMAP.C STUFF
  159. //
  160.  
  161. typedef enum
  162. {
  163.     emit_surface,
  164.     emit_point,
  165.     emit_spotlight,
  166.     emit_skylight
  167. }
  168. emittype_t;
  169.  
  170. typedef struct directlight_s
  171. {
  172.     struct directlight_s* next;
  173.     emittype_t      type;
  174.     int             style;
  175.     vec3_t          origin;
  176.     vec3_t          intensity;
  177.     vec3_t          normal;                                // for surfaces and spotlights
  178.     float           stopdot;                               // for spotlights
  179.     float           stopdot2;                              // for spotlights
  180.  
  181.     // 'Arghrad'-like features
  182.     vec_t           fade;                                  // falloff scaling for linear and inverse square falloff 1.0 = normal, 0.5 = farther, 2.0 = shorter etc
  183.     unsigned char   falloff;                               // falloff style 0 = default (inverse square), 1 = inverse falloff, 2 = inverse square (arghrad compat)
  184.  
  185.     // -----------------------------------------------------------------------------------
  186.     // Changes by Adam Foster - afoster@compsoc.man.ac.uk
  187.     // Diffuse light_environment light colour
  188.     // Really horrible hack which probably won't work!
  189. #ifdef HLRAD_WHOME
  190.     vec3_t            diffuse_intensity;
  191. #endif
  192.     // -----------------------------------------------------------------------------------
  193.  
  194. } directlight_t;
  195.  
  196. #define TRANSFER_SCALE_VAL    (USHRT_MAX/4)
  197.  
  198. #define    TRANSFER_SCALE          (1.0 / TRANSFER_SCALE_VAL)
  199. #define    INVERSE_TRANSFER_SCALE    (TRANSFER_SCALE_VAL)
  200. #define TRANSFER_SCALE_MAX    (TRANSFER_SCALE_VAL * 4)
  201.  
  202. typedef struct
  203. {
  204.     unsigned size  : 12;
  205.     unsigned index : 20;
  206. } transfer_index_t;
  207.  
  208. typedef unsigned transfer_raw_index_t;
  209. typedef float transfer_data_t;
  210.  
  211. //Special RGB mode for transfers
  212. #ifdef HLRAD_HULLU
  213.     #if defined(HLRAD_HULLU_48BIT_RGB_TRANSFERS) && defined(HLRAD_HULLU_96BIT_RGB_TRANSFERS)
  214.         #error Conflict: Both HLRAD_HULLU_48BIT_RGB_TRANSFERS and HLRAD_HULLU_96BIT_RGB_TRANSFERS defined!
  215.     #elif defined(HLRAD_HULLU_96BIT_RGB_TRANSFERS)
  216.         //96bit (no noticeable difference to 48bit)
  217.         typedef float rgb_transfer_t[3];
  218.     #else
  219.         //default.. 48bit
  220.         typedef unsigned short rgb_transfer_t[3];
  221.     #endif
  222.     
  223.     typedef rgb_transfer_t rgb_transfer_data_t;
  224. #endif
  225.  
  226. #define MAX_COMPRESSED_TRANSFER_INDEX_SIZE ((1 << 12) - 1)
  227.  
  228. #define    MAX_PATCHES    (65535*4)
  229. #define MAX_VISMATRIX_PATCHES 65535
  230. #define MAX_SPARSE_VISMATRIX_PATCHES MAX_PATCHES
  231.  
  232. typedef enum
  233. {
  234.     ePatchFlagNull = 0,
  235.     ePatchFlagOutside = 1
  236. } ePatchFlags;
  237.  
  238. typedef struct patch_s
  239. {
  240.     struct patch_s* next;                                  // next in face
  241.     vec3_t          origin;                                // Center centroid of winding (cached info calculated from winding)
  242.     vec_t           area;                                  // Surface area of this patch (cached info calculated from winding)
  243.     Winding*        winding;                               // Winding (patches are triangles, so its easy)
  244.     vec_t           scale;                                 // Texture scale for this face (blend of S and T scale)
  245.     vec_t           chop;                                  // Texture chop for this face factoring in S and T scale
  246.  
  247.     unsigned        iIndex;
  248.     unsigned        iData;
  249.  
  250.     transfer_index_t* tIndex;
  251.     transfer_data_t*  tData;
  252. #ifdef HLRAD_HULLU
  253.     rgb_transfer_data_t*    tRGBData;
  254. #endif
  255.  
  256.     int             faceNumber;
  257.     ePatchFlags     flags;
  258.  
  259. #ifdef ZHLT_TEXLIGHT
  260.     int                totalstyle[MAXLIGHTMAPS];                //LRC - gives the styles for use by the new switchable totallight values
  261.     vec3_t          totallight[MAXLIGHTMAPS];                // accumulated by radiosity does NOT include light accounted for by direct lighting
  262.     vec3_t            directlight[MAXLIGHTMAPS];                // direct light only
  263.     int                emitstyle;                               //LRC - for switchable texlights
  264.     vec3_t          baselight;                             // emissivity only, uses emitstyle
  265.     vec3_t          samplelight[MAXLIGHTMAPS];
  266.     int             samples[MAXLIGHTMAPS];                 // for averaging direct light
  267. #else
  268.     vec3_t          totallight;                            // accumulated by radiosity does NOT include light accounted for by direct lighting
  269.     vec3_t          baselight;                             // emissivity only
  270.     vec3_t          directlight;                           // direct light value
  271.  
  272.     vec3_t          samplelight;
  273.     int             samples;                               // for averaging direct light
  274. #endif
  275. } patch_t;
  276.  
  277. #ifdef ZHLT_TEXLIGHT
  278. //LRC
  279. vec3_t* GetTotalLight(patch_t* patch, int style);
  280. #endif
  281.  
  282. typedef struct
  283. {
  284.     dface_t*        faces[2];
  285.     vec3_t          interface_normal;
  286.     vec_t           cos_normals_angle;
  287.     bool            coplanar;
  288. } edgeshare_t;
  289.  
  290. extern edgeshare_t g_edgeshare[MAX_MAP_EDGES];
  291.  
  292. //
  293. // lerp.c stuff
  294. //
  295.  
  296. typedef struct lerprect_s
  297. {
  298.     dplane_t        plane; // all walls will be perpindicular to face normal in some direction
  299.     vec3_t          vertex[4];
  300. }
  301. lerpWall_t;
  302.  
  303. typedef struct lerpdist_s
  304. {
  305.     vec_t           dist;
  306.     unsigned        patch;
  307. } lerpDist_t;
  308.  
  309. // Valve's default was 2048 originally.
  310. // MAX_LERP_POINTS causes lerpTriangulation_t to consume :
  311. // 2048 : roughly 17.5Mb
  312. // 3072 : roughly 35Mb
  313. // 4096 : roughly 70Mb
  314. #define    DEFAULT_MAX_LERP_POINTS             512
  315. #define DEFAULT_MAX_LERP_WALLS           128
  316.  
  317. typedef struct
  318. {
  319.     unsigned        maxpoints;
  320.     unsigned        numpoints;
  321.  
  322.     unsigned        maxwalls;
  323.     unsigned        numwalls;
  324.     patch_t**       points;    // maxpoints
  325.     lerpDist_t*     dists;     // numpoints after points is populated
  326.     lerpWall_t*     walls;     // maxwalls
  327.  
  328.     unsigned        facenum;
  329.     const dface_t*  face;
  330.     const dplane_t* plane;
  331. }
  332. lerpTriangulation_t;
  333.  
  334. // These are bitflags for lighting adjustments for special cases
  335. typedef enum
  336. {
  337.     eModelLightmodeNull     = 0,
  338.     eModelLightmodeEmbedded = 0x01,
  339.     eModelLightmodeOpaque   = 0x02,
  340.     eModelLightmodeConcave  = 0x04
  341. }
  342. eModelLightmodes;
  343.  
  344. typedef struct
  345. {
  346.     Winding* winding;
  347.     dplane_t plane;
  348.     unsigned facenum;
  349.  
  350. #ifdef HLRAD_HULLU
  351.     vec3_t transparency_scale;
  352.     bool transparency;
  353. #endif
  354.  
  355. } opaqueList_t;
  356.  
  357. #define OPAQUE_ARRAY_GROWTH_SIZE 1024
  358.  
  359. //
  360. // qrad globals
  361. //
  362.  
  363. extern patch_t* g_face_patches[MAX_MAP_FACES];
  364. extern entity_t* g_face_entity[MAX_MAP_FACES];
  365. extern vec3_t   g_face_offset[MAX_MAP_FACES];              // for models with origins
  366. extern eModelLightmodes g_face_lightmode[MAX_MAP_FACES];
  367. extern vec3_t   g_face_centroids[MAX_MAP_EDGES];
  368. extern patch_t  g_patches[MAX_PATCHES];
  369. extern unsigned g_num_patches;
  370.  
  371. extern float    g_lightscale;
  372. extern float    g_dlight_threshold;
  373. extern float    g_coring;
  374. extern int      g_lerp_enabled;
  375.  
  376. extern void     MakeShadowSplits();
  377.  
  378. //==============================================
  379.  
  380. extern bool     g_extra;
  381. extern vec3_t   g_ambient;
  382. extern vec_t    g_direct_scale;
  383. extern float    g_maxlight;
  384. extern unsigned g_numbounce;
  385. extern float    g_qgamma;
  386. extern float    g_indirect_sun;
  387. extern float    g_smoothing_threshold;
  388. extern float    g_smoothing_value;
  389. extern bool     g_estimate;
  390. extern char     g_source[_MAX_PATH];
  391. extern vec_t    g_fade;
  392. extern int      g_falloff;
  393. extern bool     g_incremental;
  394. extern bool     g_circus;
  395. extern bool     g_sky_lighting_fix;
  396. extern vec_t    g_chop;    // Chop value for normal textures
  397. extern vec_t    g_texchop; // Chop value for texture lights
  398. extern opaqueList_t* g_opaque_face_list;
  399. extern unsigned      g_opaque_face_count;
  400. extern unsigned      g_max_opaque_face_count;    // Current array maximum (used for reallocs)
  401.  
  402. #ifdef ZHLT_PROGRESSFILE // AJM
  403. extern char*           g_progressfile ;
  404. #endif
  405.  
  406. // ------------------------------------------------------------------------
  407. // Changes by Adam Foster - afoster@compsoc.man.ac.uk
  408. #ifdef HLRAD_WHOME
  409.  
  410. extern vec3_t    g_colour_qgamma;
  411. extern vec3_t    g_colour_lightscale;
  412.  
  413. extern vec3_t    g_colour_jitter_hack;
  414. extern vec3_t    g_jitter_hack;
  415. extern bool    g_diffuse_hack;
  416. extern bool    g_spotlight_hack;
  417. extern vec3_t    g_softlight_hack;
  418. extern float    g_softlight_hack_distance;
  419.  
  420. #endif
  421. // ------------------------------------------------------------------------
  422.  
  423.  
  424. #ifdef HLRAD_HULLU
  425.     extern bool    g_customshadow_with_bouncelight;
  426.     extern bool    g_rgb_transfers;
  427. #endif
  428.  
  429. extern void     MakeTnodes(dmodel_t* bm);
  430. extern void     PairEdges();
  431. extern void     BuildFacelights(int facenum);
  432. extern void     PrecompLightmapOffsets();
  433. extern void     FinalLightFace(int facenum);
  434. extern int      TestLine(const vec3_t start, const vec3_t stop);
  435. extern int      TestLine_r(int node, const vec3_t start, const vec3_t stop);
  436. extern void     CreateDirectLights();
  437. extern void     DeleteDirectLights();
  438. extern void     GetPhongNormal(int facenum, vec3_t spot, vec3_t phongnormal);
  439.  
  440. #ifdef HLRAD_HULLU
  441. typedef bool (*funcCheckVisBit) (unsigned, unsigned, vec3_t&);
  442. #else
  443. typedef bool (*funcCheckVisBit) (unsigned, unsigned);
  444. #endif
  445. extern funcCheckVisBit g_CheckVisBit;
  446.  
  447. // qradutil.c
  448. extern vec_t    PatchPlaneDist(const patch_t* const patch);
  449. extern dleaf_t* PointInLeaf(const vec3_t point);
  450. extern void     MakeBackplanes();
  451. extern const dplane_t* getPlaneFromFace(const dface_t* const face);
  452. extern const dplane_t* getPlaneFromFaceNumber(unsigned int facenum);
  453. extern void     getAdjustedPlaneFromFaceNumber(unsigned int facenum, dplane_t* plane);
  454. extern dleaf_t* HuntForWorld(vec_t* point, const vec_t* plane_offset, const dplane_t* plane, int hunt_size, vec_t hunt_scale, vec_t hunt_offset);
  455.  
  456. // makescales.c
  457. extern void     MakeScalesVismatrix();
  458. extern void     MakeScalesSparseVismatrix();
  459. extern void     MakeScalesNoVismatrix();
  460.  
  461. // transfers.c
  462. extern unsigned g_total_transfer;
  463. extern bool     readtransfers(const char* const transferfile, long numpatches);
  464. extern void     writetransfers(const char* const transferfile, long total_patches);
  465.  
  466. // vismatrixutil.c (shared between vismatrix.c and sparse.c)
  467. extern void     SwapTransfers(int patchnum);
  468. extern void     MakeScales(int threadnum);
  469. extern void     DumpTransfersMemoryUsage();
  470. #ifdef HLRAD_HULLU
  471. extern void     SwapRGBTransfers(int patchnum);
  472. extern void     MakeRGBScales(int threadnum);
  473. #endif
  474.  
  475. // lerp.c
  476. #ifdef ZHLT_TEXLIGHT
  477. extern void     SampleTriangulation(const lerpTriangulation_t* const trian, vec3_t point, vec3_t result, int style); //LRC
  478. #else
  479. extern void     SampleTriangulation(const lerpTriangulation_t* const trian, vec3_t point, vec3_t result);
  480. #endif
  481. extern void     DestroyTriangulation(lerpTriangulation_t* trian);
  482. extern lerpTriangulation_t* CreateTriangulation(unsigned int facenum);
  483. extern void     FreeTriangulation(lerpTriangulation_t* trian);
  484.  
  485. // mathutil.c
  486. #ifdef HLRAD_HULLU
  487. extern bool     TestSegmentAgainstOpaqueList(const vec_t* p1, const vec_t* p2, vec3_t &scaleout);
  488. #else
  489. extern bool     TestSegmentAgainstOpaqueList(const vec_t* p1, const vec_t* p2);
  490. #endif
  491. extern bool     intersect_line_plane(const dplane_t* const plane, const vec_t* const p1, const vec_t* const p2, vec3_t point);
  492. extern bool     intersect_linesegment_plane(const dplane_t* const plane, const vec_t* const p1, const vec_t* const p2,vec3_t point);
  493. extern void     plane_from_points(const vec3_t p1, const vec3_t p2, const vec3_t p3, dplane_t* plane);
  494. extern bool     point_in_winding(const Winding& w, const dplane_t& plane, const vec_t* point);
  495. extern bool     point_in_wall(const lerpWall_t* wall, vec3_t point);
  496. extern bool     point_in_tri(const vec3_t point, const dplane_t* const plane, const vec3_t p1, const vec3_t p2, const vec3_t p3);
  497. extern void     ProjectionPoint(const vec_t* const v, const vec_t* const p, vec_t* rval);
  498. extern void     SnapToPlane(const dplane_t* const plane, vec_t* const point, vec_t offset);
  499.  
  500. #endif //HLRAD_H__
  501.